﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using EasyNetQ;
using EasyNetQ.AutoSubscribe;

namespace WebAppEasynetQ
{
    [Queue("wincos_1", ExchangeName = "WinCos2BuhlerSmarT")]
    public class Order
    {
        public int OrderId { get; set; }
        public string OrderNumber { get; set; }
    }

    public class OrderConsumer : IConsumeAsync<Order>
    {
        [AutoSubscriberConsumer(SubscriptionId = "OrderService")] 
        public Task ConsumeAsync(Order message, CancellationToken cancellationToken = default)
        {
            // Your business logic code here
            // eg.Generate one ZAP question records into database and send to client
            // Sample console code
            System.Console.ForegroundColor = System.ConsoleColor.Red;
            System.Console.WriteLine("Consume one message from RabbitMQ : {0}, I will generate one ZAP question list to client", message.OrderNumber);
            System.Console.ResetColor();

            return Task.CompletedTask;
        }


    }
    public class HandleConsume
    {
        public static void HandleTextMessage(Order order)
        {
            Console.WriteLine("Got message Order: {0}", order.OrderId);
            Console.WriteLine("Got message Order: {0}", order.OrderNumber);
        }
    }
}
